<?php
/**
 * 获取新闻正文信息
 * 以json方式返回
 * solosky <solosky772@qq.com>
 */

include_once("common.php");

 $pre    = $config["DB_PREX"]; 
//输出当前新闻
 $newshash = getVar($_GET, "newshash",0);
 //SQL
 $sql = "SELECT n.*,c.title AS categoryTitle, c.url AS categoryUrl,s.title AS siteTitle,s.url AS siteUrl 
 		FROM {$pre}news AS n, {$pre}category AS c, {$pre}site AS s
		WHERE n.categoryhash=c.categoryhash AND c.sitehash=s.sitehash AND n.newshash={$newshash} LIMIT 1";
 $db->query($sql);
 $cnt = $db->getRowsNum(); 
 $news = $db->getOneRow();
 //查询上一条和下一条
 $presql = "SELECT newshash,title,date FROM {$pre}news WHERE categoryhash={$news['categoryhash']} AND  date>{$news['date']} AND newshash!={$news['newshash']}  ORDER BY date ASC LIMIT 1";
 $db->query($presql);
 $preNews = $db->getOneRow();
 $nextsql = "SELECT newshash,title,date FROM {$pre}news WHERE categoryhash={$news['categoryhash']} AND  date<{$news['date']} AND newshash!={$news['newshash']}  ORDER BY date DESC LIMIT 1";
 $db->query($nextsql);
 $nextNews = $db->getOneRow();
 $ret = array(
		"success" =>$cnt?"true":"false",
		"data" =>array(
					   "news"=>$news,
						"pre"=>$preNews,
						"next"=>$nextNews
				)
);
 exit(json_encode($ret));


?>